﻿

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>我的出售</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

    <div class="layui-fluid">
        <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief">
            <ul class="layui-tab-title">
                <li class="layui-this" lay-id="1">新增订单</li>
                <li lay-id="2">出售订单</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item  layui-show">
                    <div class="layui-card">
                        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                            <div class="layui-form-item ">
                                <div class="layui-inline layui-col-lg2">
                                    <label class="layui-form-label">单号</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="docno" id="docno" placeholder="单据编号" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline layui-col-lg2">
                                    <label class="layui-form-label">经销商名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="customer_name" id="customer_name" placeholder="经销商名称" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline layui-col-lg2">
                                    <label class="layui-form-label">款号</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="productvalue" id="productvalue" placeholder="款号" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline layui-col-lg2">
                                    <label class="layui-form-label">审批状态</label>
                                    <div class="layui-input-block">
                                        <select name="status" id="status">
                                            <option value="" selected> 全部</option>
                                            <option value="0">待发布</option>
                                            <option value="1">发布</option>
                                        </select>
                                    </div>
                                </div>
                                <!--<div class="layui-inline layui-col-lg2">
                        <label class="layui-form-label">流程状态</label>
                        <div class="layui-input-block">
                            <select name="lczt" id="lczt">
                                <option value="">全部</option>
                                <option value="0">待办</option>
                                <option value="2">已办</option>
                            </select>
                        </div>
                    </div>-->
                                <div class="layui-inline layui-col-lg1">
                                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body">
                            <div style="padding-bottom: 10px;">
                                <!--<button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel">删除</button>-->
                                <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">新增订单</button>
                            </div>

                            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
                            <script type="text/html" id="buttonTpl">
                                {{#  if(d.status == 99){ }}
                                <button class="layui-btn layui-btn-xs">已审核</button>
                                {{#  } else if(d.status == 1){ }}
                                <button class="layui-btn layui-btn-xs">已发布</button>
                                {{#  } else if(d.status == 0){ }}
                                <button class="layui-btn layui-btn-danger layui-btn-xs">未发布</button>
                                {{#  } else if(d.status == -1){ }}
                                <button class="layui-btn layui-btn-danger layui-btn-xs">驳回</button>
                                {{#  } else { }}
                                <button class="layui-btn layui-btn-primary layui-btn-xs">未审核</button>
                                {{#  } }}
                            </script>

                            <script type="text/html" id="test-table-operate-td">
                                {{#  if(d.status == 0){ }}
                                <a class="layui-btn layui-btn-xs" lay-event="release">发布</a>
                                <!--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
                                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                                <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="copy">复制订单</a>-->
                                {{#  } else if(d.status == 1){ }}
                                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                                <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="copy">复制订单</a>-->
                                {{#  } else { }}
                                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                                <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="copy">复制订单</a>-->
                                {{#  } }}
                            </script>

                            <script type="text/html" id="imgTpl">
                                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
                            </script>
                        </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-card">
                        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                            <div class="layui-form-item ">
                                <div class="layui-inline layui-col-lg2">
                                    <label class="layui-form-label">单号</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="docno" id="docno" placeholder="单据编号" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline layui-col-lg2">
                                    <label class="layui-form-label">经销商名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="customer_name" id="customer_name" placeholder="经销商名称" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline layui-col-lg2">
                                    <label class="layui-form-label">款号</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="productvalue" id="productvalue" placeholder="款号" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline layui-col-lg2">
                                    <label class="layui-form-label">审批状态</label>
                                    <div class="layui-input-block">
                                        <select name="status" id="status">
                                            <option value="" selected> 全部</option>
                                            <option value="0">待发布</option>
                                            <option value="1">发布</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline layui-col-lg1">
                                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body">

                            <table id="LAY-user-manage-forsale" lay-filter="LAY-user-manage-forsale"></table>
                            <script type="text/html" id="buttonTpl_sale">
                                {{#  if(d.status == 99){ }}
                                <button class="layui-btn layui-btn-xs">已完成</button>
                                {{#  } else if(d.status == 90){ }}
                                <button class="layui-btn layui-btn-primary layui-btn-xs">失败</button>
                                {{#  } else if(d.status == 0){ }}
                                <button class="layui-btn layui-btn-primary layui-btn-xs">待填写发货信息</button>
                                {{#  } else if(d.status == -1){ }}
                                <button class="layui-btn layui-btn-danger layui-btn-xs">驳回</button>
                                {{#  } else { }}
                                <button class="layui-btn layui-btn-primary layui-btn-xs">未审核</button>
                                {{#  } }}
                            </script>

                            <script type="text/html" id="test-table-operate-td-forsale">
                                {{#  if(d.status == 0){ }}
                                <a class="layui-btn layui-btn-xs" lay-event="writefhinfo">填写发货信息</a>
                                <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>-->
                                {{#  } else if(d.status == 99){ }}
                                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>

                                {{#  } else { }}
                                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                                <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="copy">复制订单</a>-->
                                {{#  } }}
                            </script>

                            <script type="text/html" id="imgTpl">
                                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
                            </script>
                        </div>
                    </div>
                </div>

            </div>
       </div>

        </div>
        <script src="../../layuiadmin/layui/layui.js"></script>
        <script src="../../layuiadmin/js/cookie.js"></script>
        <script>
            var clickCount = 0;
            layui.config({
                base: '../../layuiadmin/' //静态资源所在路径
            }).extend({
                index: 'lib/index' //主入口模块
            }).use(['index', 'useradmin', 'util', 'table', 'laypage', 'dropdown'], function () {
                var $ = layui.$
                    , form = layui.form
                    , table = layui.table
                    , laypage = layui.laypage
                    , util = layui.util
                    , element = layui.element
                    , dropdown = layui.dropdown;

                /* 触发事件 */
                //var active = {
                //    tabChange_kssj: function () {
                //        /* 切换到指定Tab项 */
                //        element.tabChange('component-tabs-brief', '2');
                //    },
                //    tabChange_ccxx: function () {
                //        /* 切换到指定Tab项 */
                //        element.tabChange('component-tabs-brief', '3');
                //    },
                //    tabChange_yljm: function () {
                //        /* 切换到指定Tab项 */
                //        element.tabChange('component-tabs-brief', '4');
                //    }
                //};
                //点击tab事件
                element.on('tab(component-tabs-brief)', function (obj) {
                    debugger
                    if (obj.index == 1) {
                        debugger
                        //数据列表加载
                        //待出售数据列表加载
                        table.render({
                            elem: '#LAY-user-manage-forsale'
                            , id: 'testReload-forsale'//容器的ID
                            , url: 'ashx/list.ashx?type=getforsalelist&loginids=' + $.cookie("loginid")
                            , toolbar: '#test-table-radio-toolbarDemo'
                            , method: 'POST'
                            , page: true
                            , limits: [10, 20, 30]
                            , limit: 10
                            , cols: [[
                                { type: 'radio' }
                                , { field: 'id', hide: true }
                                , { field: 'docno', width: 130, title: '单据编号', align: 'center' }
                                , { field: 'buyname', width: 150, title: '买方', align: 'center' }
                                , { field: 'salename', width: 150, title: '出售方', align: 'center' }
                                , { field: 'sl', width: 80, title: '数量', align: 'center' }
                                , { field: 'status', width: 150, title: '状态', templet: '#buttonTpl_sale', align: 'center' }
                                , { field: 'bjmsg', width: 100, title: '返回消息', align: 'center' }
                                , { field: 'recename', width: 100, title: '收货联系人', align: 'center' }
                                , { field: 'recetel', width: 100, title: '收货联系电话', align: 'center' }
                                , { field: 'receaddress', width: 100, title: '收货地址', align: 'center' }
                                , { field: 'typename', width: 100, title: '快递公司', align: 'center' }
                                , { field: 'kd_name', width: 100, title: '发货联系人', align: 'center' }
                                , { field: 'kd_docno', width: 100, title: '快递单号', align: 'center' }
                                , { field: 'kd_tel', width: 100, title: '发货联系电话', align: 'center' }
                                , { field: 'createtime', width: 160, title: '创建时间', align: 'center', sort: true }
                                , { field: 'sendtime', width: 160, title: '发货时间', align: 'center', sort: true }
                                , { width: 200, align: 'center', fixed: 'right', toolbar: '#test-table-operate-td-forsale' }
                            ]], parseData: function (res) { //将原始数据解析成 table 组件所规定的数据.
                                return {
                                    "code": res.code, //解析接口状态
                                    "msg": res.msg, //解析提示文本
                                    "count": res.count, //解析数据长度
                                    "data": res.data //解析数据列表
                                };
                            }
                            , where: {
                                docno: $('#docno').val()
                                , customer_name: $('#customer_name').val()
                                , productvalue: $('#productvalue').val()
                                , status: $("select[name='status']").val()
                            }
                        });
                        //监听工具条-待出售
                        table.on('tool(LAY-user-manage-forsale)', function (obj) {
                            debugger
                            var data = obj.data;
                            //查看明细
                            if (obj.event === 'detail') {
                                var index = layer.open({
                                    type: 2
                                    , title: '查看'
                                    , content: 'buyviews.html?docnos=' + data.docno
                                    , maxmin: true
                                    , area: [($(window).width() * 1) + 'px', ($(window).height() * 1) + 'px']
                                    , cancel: function (index, layero) {

                                    },
                                    end: function () {

                                    }
                                });
                                layer.full(index);
                            }
                            //填写发货信息
                            else if (obj.event === 'writefhinfo') {
                                var index = layer.open({
                                    type: 2
                                    , title: '待售列表'
                                    , content: 'forsalelist.html?ids=' + data.id
                                    , maxmin: true
                                    , btn: ["确定", '关闭']
                                    , area: [($(window).width() * 0.9) + 'px', ($(window).height() * 0.9) + 'px']
                                    , yes: function (index, layero) {
                                        var objdata = $(layero).find("iframe")[0].contentWindow;
                                        $(layero).find("iframe")[0].contentWindow.$('#saveBtn_js').click();//执行子页面的按钮点击事件
                                        //var mJson = objdata.$('#uidsub').val();//获取子页面绑定的值
                                        var sel_kdgs = objdata.$('#sel_kdgs').val();//快递公司
                                        var txt_kddh = objdata.$('#txt_kddh').val();//快递单号
                                        var txt_name = objdata.$('#txt_name').val();//联系人
                                        var txt_tel = objdata.$('#txt_tel').val();//联系电话
                                        var txt_id = objdata.$('#txt_id').val();//id

                                        if (sel_kdgs === "" || sel_kdgs === null || sel_kdgs === undefined) {
                                            layer.msg('快递公司不能为空', { icon: 5 });
                                            return false;
                                        }
                                        if (txt_kddh === "" || txt_kddh === null || txt_kddh === undefined) {
                                            layer.msg('快递单号不能为空', { icon: 5 });
                                            return false;
                                        }
                                        if (txt_name === "" || txt_name === null || txt_name === undefined) {
                                            layer.msg('联系人不能为空', { icon: 5 });
                                            return false;
                                        }
                                        if (txt_tel === "" || txt_tel === null || txt_tel === undefined) {
                                            layer.msg('联系电话不能为空', { icon: 5 });
                                            return false;
                                        }
                                        //if (mJson != "") {
                                        // var _mJson = $.parseJSON(mJson);//转成Json对象
                                        //主体信息
                                        var arrayObj_main = new Array();
                                        var main = {
                                            "id": $.cookie("id"),
                                            "loginid": $.cookie("loginid"),
                                            "username": $.cookie("username"),
                                            "sel_kdgs": sel_kdgs,
                                            "txt_kddh": txt_kddh,
                                            "txt_name": txt_name,
                                            "txt_tel": txt_tel,
                                            "txt_id": txt_id
                                        };
                                        arrayObj_main.push(main);
                                        $.ajax({
                                            type: "post",
                                            async: true,
                                            url: 'ashx/list.ashx?type=forsale',
                                            data: JSON.stringify({ 'ArrayObj_main': arrayObj_main }),
                                            dataType: "json",
                                            success: function (res) {
                                                var index = parent.layer.getFrameIndex(window.name);
                                                if (res.flag == "True") {
                                                    clickCount++;
                                                    layer.msg(res.remsg, {
                                                        time: 2000,
                                                        end: function () {
                                                            parent.layer.close(index);
                                                            window.parent.location.reload();
                                                        }
                                                    })
                                                }
                                                else {
                                                    layer.alert(res.remsg);
                                                }
                                            }
                                        })
                                        //}
                                    },
                                    cancel: function (index, layero) {

                                    },
                                    end: function () {
                                        table.reload('testReload', {//刷新列表
                                            where: { //请求参数
                                                lddocno: $('#lddocno').val()
                                                , dcname: $('#dcname').val()
                                                , gkname: $('#gkname').val()
                                                , status: $("select[name='status']").val()
                                            }
                                        });
                                    }
                                });
                            }

                        });
                    }
                    //layer.msg(obj.index + '：' + this.innerHTML);
                });
                //验证用户是否登录
                if ($.cookie("loginid") == "" || $.cookie("loginid") == null || $.cookie("loginid") == "null" || $.cookie("loginid") == undefined || $.cookie("loginid") == "undefined") {
                    $.removeCookie("id", { path: "/", sucue: true });//用户id
                    $.removeCookie("loginid", { path: "/", sucue: true });//登录账号
                    $.removeCookie("username", { path: "/", sucue: true });//用户名
                    $.removeCookie("role", { path: "/", sucue: true });//权限
                    $.removeCookie("islookme", { path: "/", sucue: true });//权限
                    window.location.href = "../login/login.html";
                }
                table.render({
                    elem: '#LAY-user-manage'
                    , id: 'testReload'//容器的ID
                    , url: 'ashx/list.ashx?type=getlist&loginids=' + $.cookie("loginid")
                    , toolbar: '#test-table-radio-toolbarDemo'
                    , method: 'POST'
                    , page: true
                    , limits: [10, 20, 30]
                    , limit: 10
                    , cols: [[
                        { type: 'radio' }
                        , { field: 'id', width: 60, title: 'id', align: 'center' }
                        , { field: 'docno', width: 130, title: '单据编号', align: 'center' }
                        , { field: 'username', width: 150, title: '出售方', align: 'center' }
                        , { field: 'sl', width: 100, title: '数量', align: 'center' }
                        , { field: 'status', width: 100, title: '状态', templet: '#buttonTpl', align: 'center' }
                        , { field: 'username', width: 90, title: '创建人', align: 'center' }
                        , { field: 'createtime', width: 160, title: '创建时间', align: 'center', sort: true }
                        , { field: 'releasetime', width: 160, title: '发布时间', align: 'center', sort: true }
                        , { width: 300, align: 'center', fixed: 'right', toolbar: '#test-table-operate-td' }
                    ]], parseData: function (res) { //将原始数据解析成 table 组件所规定的数据.
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": res.count, //解析数据长度
                            "data": res.data //解析数据列表
                        };
                    }
                    , where: {
                        docno: $('#docno').val()
                        , customer_name: $('#customer_name').val()
                        , productvalue: $('#productvalue').val()
                        , status: $("select[name='status']").val()
                    }
                });
           
              

              
                //监听排序
                table.on('sort(LAY-user-manage)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                    table.reload('testReload', {//刷新列表
                        initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
                        , where: { //请求参数
                            field: obj.field //排序字段
                            , order: obj.type //排序方式
                            , docno: $('#docno').val()
                            , customer_name: $('#customer_name').val()
                            , productvalue: $('#productvalue').val()
                            , status: $("select[name='status']").val()
                        }
                    });
                });

                //双击行事件
                table.on('rowDouble(LAY-user-manage)', function (obj) {
                    //console.log(obj.tr) //得到当前行元素对象
                    //console.log(obj.data) //得到当前行数据
                    layer.open({
                        type: 2
                        , title: '查看'
                        , content: 'select_view.html?&dj_docno=' + obj.data.docno
                        , maxmin: true
                        , area: [($(window).width() * 0.7) + 'px', ($(window).height() * 0.7) + 'px']
                        , cancel: function (index, layero) {

                        },
                        end: function () {

                        }
                    });
                    //obj.del(); //删除当前行
                    //obj.update(fields) //修改当前行数据
                });
                //出售订单明细
                table.on('tool(LAY-user-manage-forsale)', function (obj) {
                    var data = obj.data;
                    //查看明细
                    if (obj.event === 'detail') {
                        var index = layer.open({
                            type: 2
                            , title: '查看'
                            , content: 'buyviews.html?type=view&docnos=' + data.docno
                            , maxmin: true
                            , area: [($(window).width() * 0.8) + 'px', ($(window).height() * 0.8) + 'px']
                            , cancel: function (index, layero) {

                            },
                            end: function () {

                            }
                        });
                        //layer.full(index);
                    }
                })
                //监听工具条-新增订单
                table.on('tool(LAY-user-manage)', function (obj) {
                    var data = obj.data;
                    //查看明细
                    if (obj.event === 'detail') {
                        var index = layer.open({
                            type: 2
                            , title: '查看'
                            , content: 'saleviews.html?type=view&docnos=' + data.docno 
                            , maxmin: true
                            , area: [($(window).width() * 0.8) + 'px', ($(window).height() * 0.8) + 'px']
                            , cancel: function (index, layero) {

                            },
                            end: function () {

                            }
                        });
                        //layer.full(index);
                    }
                    //发布
                    else if (obj.event === 'release') {
                        layer.confirm('您确定要发布吗', function (index) {
                            $.ajax({
                                url: 'ashx/list.ashx?type=release&getids=' + data.id,
                                type: "post",
                                contentType: "application/json",
                                dataType: "json",
                                data: {},
                                success: function (res) {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    if (res.flag == "True") {
                                        layer.msg(res.remsg, {
                                            time: 2000,
                                            end: function () {
                                                table.reload('testReload', {//刷新列表
                                                    where: { //请求参数
                                                        docno: $('#docno').val()
                                                        , customer_name: $('#customer_name').val()
                                                        , productvalue: $('#productvalue').val()
                                                        , status: $("select[name='status']").val()
                                                    }
                                                });
                                            }
                                        })
                                    }
                                    else {
                                        layer.alert(res.remsg);
                                    }
                                }
                            });
                        });
                    }
                    //删除，实际是改为不可用
                    else if (obj.event === 'del') {
                        layer.confirm('您确定要删除吗', function (index) {
                            $.ajax({
                                url: 'ashx/list.ashx?type=delete_salelist&getids=' + data.id ,
                                type: "post",
                                contentType: "application/json",
                                dataType: "json",
                                data: {},
                                success: function (res) {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    if (res.flag == "True") {
                                        layer.msg(res.remsg, {
                                            time: 2000,
                                            end: function () {
                                                table.reload('testReload', {//刷新列表
                                                    where: { //请求参数
                                                        docno: $('#docno').val()
                                                        , customer_name: $('#customer_name').val()
                                                        , productvalue: $('#productvalue').val()
                                                        , status: $("select[name='status']").val()
                                                    }
                                                });
                                            }
                                        })
                                    }
                                    else {
                                        layer.alert(res.remsg);
                                    }
                                }
                            });
                        });
                    }
                    //修改
                    else if (obj.event === 'edit') {
                        var index = layer.open({
                            type: 2
                            , title: '修改'
                            , content: 'edit.html?type=edit&editid=' + data.id + '&djbhs=' + data.docno
                            , maxmin: true
                            , area: [($(window).width() * 1) + 'px', ($(window).height() * 1) + 'px']
                            , cancel: function (index, layero) {
                                //取消的操作
                                var body = layer.getChildFrame('body', index);
                                var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象，执行iframe页的方法：
                                var content = layero.find("iframe")[0].contentWindow.$("#lbl_ysdh").text();
                                if (content == "" || content == null || content == undefined) {

                                }
                                else {
                                    //iframeWin.submit('save');//调用子页面的方法，得到子页面返回的ids
                                    layer.close(index);//需要手动关闭窗口
                                }
                            },
                            end: function () {
                                table.reload('testReload', {//刷新列表
                                    where: { //请求参数
                                        docno: $('#docno').val()
                                        , customer_name: $('#customer_name').val()
                                        , productvalue: $('#productvalue').val()
                                        , status: $("select[name='status']").val()
                                    }
                                });
                            }
                        });
                        layer.full(index);
                        //layer.alert('编辑行：<br>' + JSON.stringify(data))
                    }
                    //复制订单
                    else if (obj.event === 'copy') {
                
                        layer.confirm('您确定要复制吗', function (index) {
                            $.ajax({
                                url: 'ashx/list.ashx?type=copy&getids=' + data.id,
                                type: "post",
                                contentType: "application/json",
                                dataType: "json",
                                data: {},
                                success: function (res) {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    if (res.flag == "True") {
                                        layer.msg(res.remsg, {
                                            time: 2000,
                                            end: function () {
                                                table.reload('testReload', {//刷新列表
                                                    where: { //请求参数
                                                        docno: $('#docno').val()
                                                        , customer_name: $('#customer_name').val()
                                                        , productvalue: $('#productvalue').val()
                                                        , status: $("select[name='status']").val()
                                                    }
                                                });
                                            }
                                        })
                                    }
                                    else {
                                        layer.alert(res.remsg);
                                    }
                                }
                            });
                        });
                    }
                });
                //监听搜索
                form.on('submit(LAY-user-front-search)', function (data) {
                    var field = data.field;
                    //执行重载
                    table.reload('testReload', {
                        where: {
                            docno: $('#docno').val()
                            , customer_name: $('#customer_name').val()
                            , productvalue: $('#productvalue').val()
                            , status: $("select[name='status']").val()

                        }, page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                });
                function getRowFexId(value) {
                    var checkStatus = table.checkStatus('testReload')
                        , data = checkStatus.data, arr = new Array();;
                    for (var i = 0; i < data.length; i++) {
                        arr.push(data[i][value]);
                    }
                    return arr.join(",");
                }
                //事件
                var active = {
                    batchdel: function () {
                        var checkStatus = table.checkStatus('testReload')
                            , checkData = checkStatus.data; //得到选中的数据
                        if (checkData.length === 0) {
                            return layer.msg('请选择数据');
                        }
                        var getid = getRowFexId("id");
                        layer.confirm('确定删除吗？', function (index) {
                            //执行 Ajax 后重载
                            $.ajax({
                                url: 'ashx/list.ashx?type=delete&getids=' + getid,
                                type: "post",
                                contentType: "application/json",
                                dataType: "json",
                                data: {},
                                success: function (res) {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    if (res.flag == "True") {
                                        layer.msg(res.remsg, {
                                            time: 2000,
                                            end: function () {
                                                table.reload('testReload', {//刷新列表
                                                    where: { //请求参数
                                                        docno: $('#docno').val()
                                                        , customer_name: $('#customer_name').val()
                                                        , productvalue: $('#productvalue').val()
                                                        , status: $("select[name='status']").val()
                                                    }
                                                });
                                            }
                                        })
                                    }
                                    else {
                                        layer.alert(res.remsg);
                                    }
                                }
                            });
                        });
                    }
                    , add: function () {
                        var index = layer.open({
                            type: 2
                            , title: '新增订单'
                            , content: 'add_product.html'
                            , maxmin: true
                            , area: [($(window).width() * 0.5) + 'px', ($(window).height() * 0.5) + 'px']
                            , cancel: function (index, layero) {
                                debugger
                                //取消的操作
                                //var body = layer.getChildFrame('body', index);
                                //var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象，执行iframe页的方法：
                                //var content = layero.find("iframe")[0].contentWindow.$("#lbl_ysdh").text();
                                //if (content == "" || content == null || content == undefined) {
                                //}
                                //else {
                                //    //iframeWin.submit('save');//调用子页面的方法，得到子页面返回的ids
                                //    layer.close(index);//需要手动关闭窗口
                                //}
                                layer.close(index);//需要手动关闭窗口
                            },
                            end: function () {
                                debugger
                                table.reload('testReload', {//刷新列表
                                    where: { //请求参数
                                        lddocno: $('#lddocno').val()
                                        , dcname: $('#dcname').val()
                                        , gkname: $('#gkname').val()
                                        , status: $("select[name='status']").val()
                                    }
                                });
                            }
                        });
                        layer.full(index);
                    }
                };

                $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
                    var type = $(this).data('type');
                    active[type] ? active[type].call(this) : '';
                });
            });
        </script>
</body>
</html>
